package com.threadDemo;

public class SynchronizedDemo implements Runnable {


    private int count=0;


        public void synchro(){

            synchronized(this) {

                for (int i = 0; i < 10; i++) {

                    try {
                        System.out.println(Thread.currentThread().getName() + ":" + count++);
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    public void unSyn(){
      //  synchronized(this) {
            for (int i = 0; i < 10; i++) {

                try {
                    System.out.println(Thread.currentThread().getName() + ":" + count);
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
   //     }
    }




    @Override
    public void run() {

            String threadName = Thread.currentThread().getName();

            if("A".equals(threadName)){
                synchro();
            }else if("B".equals(threadName)){
                unSyn();

            }


    }

    public static void main(String[] args) {
        SynchronizedDemo synchronizedDemo = new SynchronizedDemo();
        Thread thread1 = new Thread(synchronizedDemo,"A");
        Thread thread2 = new Thread(synchronizedDemo,"B");

        thread1.start();
        thread2.start();
    }
}
